package com.example.util;

import com.example.dao.InventoryDao;
import com.example.dao.OrderdateilDao;
import com.example.entity.Inventory;
import com.example.entity.Orderdateil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Component
public class Savesession {
    @Resource
    InventoryDao inventoryDao;
    @Resource
    OrderdateilDao orderdateilDao;

    //库存信息
    public int getInventory(int goodsid,HttpServletRequest request){
        int kc = 0;
        //入库总数
        int intotal = 0;
        HashMap inmap = new HashMap();
        inmap.put("goodsid", goodsid);
        inmap.put("flag", "in");
        List<Inventory> inlist = inventoryDao.selectAll(inmap);
        for(Inventory inventory:inlist){
            intotal += inventory.getNum();
        }
        //出库总数
        int outtotal = 0;
        HashMap outmap = new HashMap();
        outmap.put("goodsid", goodsid);
        outmap.put("flag", "out");
        List<Inventory> outlist = inventoryDao.selectAll(outmap);
        for(Inventory inventory:outlist){
            outtotal += inventory.getNum();
        }
        kc = intotal-outtotal;
        return kc;
    }

    //菜品销量
    public int getGoodsXlnum(int goodsid,HttpServletRequest request){
        int xlnum = 0;
        //计算菜品销量
        HashMap map = new HashMap();
        map.put("goodsid", goodsid);
        map.put("status", "交易完成");
        List<Orderdateil> orlist = orderdateilDao.selectAll(map);
        for (Orderdateil orderdateil : orlist) {
            xlnum+=orderdateil.getSlnum();
        }
        return xlnum;
    }



}




